package edu.yzu.testspringboot002.controller;

import cn.hutool.json.JSONObject;

import edu.yzu.testspringboot002.po.Doctor;
import edu.yzu.testspringboot002.po.WeChatDTO;
import edu.yzu.testspringboot002.po.dto.PasswordUpdateDTO;
import edu.yzu.testspringboot002.po.vo.AppUserInfo;
import edu.yzu.testspringboot002.po.vo.AppUserVO;
import edu.yzu.testspringboot002.service.WeChatUserService;
import edu.yzu.testspringboot002.utils.ResponseResult;
import edu.yzu.testspringboot002.utils.group.GroupQuery;
import edu.yzu.testspringboot002.utils.group.GroupUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 */
@RestController
@RequestMapping("/wechat/client")
public class LoginController {

   @Autowired
    private WeChatUserService weChatUserService;




    @PostMapping("/getWeChat")
    public ResponseResult<JSONObject> getWeChat(@RequestBody  @Validated WeChatDTO weChatDTO){
        //return ResponseResult.ok(weChatUserService.getWeChat(weChatDTO));
        return null;
    }



    @PostMapping("/bindWeChat")
    public ResponseResult<Void> bindWeChat(@RequestBody  @Validated({GroupUpdate.class}) WeChatDTO weChatDTO){
        //weChatUserService.bindWeChat(weChatDTO);
        return ResponseResult.ok();
    }


    @PostMapping("/updatePassword")
    public ResponseResult<Void> updatePassword(@RequestBody  @Validated PasswordUpdateDTO passwordUpdateDTO){
        //weChatUserService.updatePassword(passwordUpdateDTO);
        return ResponseResult.ok();
    }



    @PostMapping("/loginPhone")
    public ResponseResult<AppUserVO> loginPhone(@RequestBody  @Validated({GroupQuery.class}) WeChatDTO weChatDTO){
        try {
            AppUserVO appUserVO= weChatUserService.loginPhone(weChatDTO);
            return ResponseResult.ok(appUserVO);
        } catch (Exception e) {
            //throw new RuntimeException(e);
            e.printStackTrace();
            return ResponseResult.failed(e.getMessage());
        }
    }

    @PostMapping("/getUserIfo")
    public ResponseResult<AppUserVO> getUserIfo(@RequestBody WeChatDTO weChatDTO){
//        return ResponseResult.ok(weChatUserService.getUserIfo(weChatDTO));
        return null;
    }


    @PostMapping("/getUserInfoByOpenId")
    public ResponseResult<AppUserVO> getUserInfoByOpenId(@RequestBody WeChatDTO weChatDTO){
//        return ResponseResult.ok(weChatUserService.getUserIfo(weChatDTO));
        return null;
    }

   //logout  退出登录 param is string :openId 返回值：void  useing get
    @GetMapping("/logout/{openId}")
    public ResponseResult<Void> logout(@PathVariable String openId){

        try {
          //  weChatUserService.logout(openId);
            return ResponseResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.failed();
        }

    }





    @PostMapping("/getPhone")
    public ResponseResult<AppUserInfo> getPhone(@RequestBody  @Validated WeChatDTO weChatDTO){
//        return ResponseResult.ok(weChatUserService.getPhone(weChatDTO));
        return null;
    }


    @PostMapping("/getUserByWxPhoneCode")
    public ResponseResult<AppUserInfo> getUserByWxPhoneCode(@RequestBody WeChatDTO weChatDTO){
       // return ResponseResult.ok(weChatUserService.getUserByWxPhoneCode(weChatDTO));
        return null;
    }


    @PostMapping("/codeToPhone/{code}")
    public ResponseResult<String> codeToPhone(@PathVariable String code){
//        return ResponseResult.ok(weChatUserService.codeToPhone(code));
        return null;
    }
    @PostMapping("/codeToOpenid/{code}")
    public ResponseResult<Doctor> codeToOpenid(@PathVariable String code){
//        return ResponseResult.ok(weChatUserService.codeToOpenid(code));
        return null;
    }
}
